<!DOCTYPE html>
<html>
<head>
    <title>Graphite Crystal Neutron Scattering</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        canvas {
            border: 1px solid #ccc;
            background-color: #fff;
        }
    </style>
</head>
<body>
    <canvas id="physicsCanvas" width="650" height="450"></canvas>
    <script>
        const canvas = document.getElementById('physicsCanvas');
        const ctx = canvas.getContext('2d');

        // Function to draw an arrow
        function drawArrow(ctx, fromx, fromy, tox, toy) {
            const headlen = 15; // length of head in pixels
            const dx = tox - fromx;
            const dy = toy - fromy;
            const angle = Math.atan2(dy, dx);
            
            // Main line
            ctx.beginPath();
            ctx.moveTo(fromx, fromy);
            ctx.lineTo(tox, toy);
            ctx.stroke();

            // Arrowhead
            ctx.beginPath();
            ctx.moveTo(tox, toy);
            ctx.lineTo(tox - headlen * Math.cos(angle - Math.PI / 7), toy - headlen * Math.sin(angle - Math.PI / 7));
            ctx.moveTo(tox, toy);
            ctx.lineTo(tox - headlen * Math.cos(angle + Math.PI / 7), toy - headlen * Math.sin(angle + Math.PI / 7));
            ctx.stroke();
        }

        // --- Start Drawing ---
        ctx.lineWidth = 2.5;
        ctx.strokeStyle = 'black';
        ctx.fillStyle = 'black';

        // 1. Draw the graphite crystal rectangle
        const rectX = 120;
        const rectY = 150;
        const rectWidth = 400;
        const rectHeight = 100;
        ctx.strokeRect(rectX, rectY, rectWidth, rectHeight);

        // 2. Draw the text inside the rectangle
        ctx.font = "30px 'Times New Roman', serif";
        ctx.textAlign = 'center';
        ctx.fillText("graphite", rectX + rectWidth * 0.28, rectY + rectHeight * 0.55);
        ctx.fillText("crystal", rectX + rectWidth * 0.72, rectY + rectHeight * 0.55);
        
        // 3. Draw incoming arrows
        const startX_in = 40;
        const endX_in = rectX;
        drawArrow(ctx, startX_in, rectY + 20, endX_in, rectY + 20);
        drawArrow(ctx, startX_in, rectY + 50, endX_in, rectY + 50);
        drawArrow(ctx, startX_in, rectY + 80, endX_in, rectY + 80);

        // 4. Draw outgoing arrow from the end
        const startX_out_end = rectX + rectWidth;
        const endX_out_end = startX_out_end + 80;
        drawArrow(ctx, startX_out_end, rectY + 50, endX_out_end, rectY + 50);

        // 5. Draw outgoing arrows from the sides
        // Top arrows
        drawArrow(ctx, rectX + 90, rectY, rectX + 140, rectY - 50);
        drawArrow(ctx, rectX + 290, rectY, rectX + 340, rectY - 50);
        
        // Bottom arrows
        drawArrow(ctx, rectX + 110, rectY + rectHeight, rectX + 160, rectY + rectHeight + 50);
        drawArrow(ctx, rectX + 310, rectY + rectHeight, rectX + 360, rectY + rectHeight + 50);

        // 6. Draw the figure caption
        ctx.font = "24px 'Courier New', monospace";
        ctx.fillText("Fig. 4.11", canvas.width / 2, 400);

    </script>
</body>
</html>